package cn.com.zhuoyan.control;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.com.zhuoyan.entity.Account;
import cn.com.zhuoyan.service.LoginService;
import cn.com.zhuoyan.solr.SolrUtile;
import cn.com.zhuoyan.util.Page;

@Controller
@RequestMapping("/goOn")
public class LoginControl {
	@Autowired
	private LoginService loginService;

	@RequestMapping("/login.html")
	public String demo(Account acocunt) throws Exception{
		int num=loginService.insert(acocunt);
		String str="redirect:/erro.jsp";
		if(num > 0){
			str="redirect:/index.jsp";
		}
		return str;
	}
	@RequestMapping("/main.html")
	public String showPage(int currentPages,int pageSize,ModelMap mv){
		String str="from Account";
		try {
			Page<Account> page=loginService.showPage(str, currentPages, pageSize, null);
			mv.addAttribute("page", page);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "index";
	}
	@RequestMapping("/solr.html")
	public void testSolr(String key,String value) throws Exception{
		SolrUtile utile=new SolrUtile();
		Map<String,String> map=new HashMap<String,String>();
		map.put(key, value);
		utile.seacher(map);
	}
}
